#include "pch.h"

#include "iosystem/uri.h"



namespace IO
{

	///
	URI::URI():
m_isEmpty(true)
{

}


///
URI::URI(const Helper::String &rhs):
m_isEmpty(true)
{
	this->Split(rhs);
}


///
URI::URI(const IO::URI &rhs):
m_isEmpty(rhs.m_isEmpty),
	m_scheme(rhs.m_scheme),
	m_userinfo(rhs.m_userinfo),
	m_host(rhs.m_host),
	m_port(rhs.m_port),
	m_localpath(rhs.m_localpath),
	m_fragment(rhs.m_fragment),
	m_query(rhs.m_query)
{

}



///
void URI::operator =(const IO::URI &rhs)
{
	this->m_isEmpty = rhs.m_isEmpty;
	this->m_scheme = rhs.m_scheme;
	this->m_userinfo = rhs.m_userinfo;
	this->m_host = rhs.m_host;
	this->m_port = rhs.m_port;
	this->m_localpath = rhs.m_localpath;
	this->m_fragment = rhs.m_fragment;
	this->m_query = rhs.m_query;
}


///
bool URI::operator ==(const IO::URI &rhs) const
{
	return ((this->m_isEmpty == rhs.m_isEmpty) &&
		(this->m_scheme == rhs.m_scheme) &&
		(this->m_userinfo == rhs.m_userinfo) &&
		(this->m_host == rhs.m_host) &&
		(this->m_port == rhs.m_port) &&
		(this->m_localpath == rhs.m_localpath) &&
		(this->m_fragment == rhs.m_fragment) &&
		(this->m_query == rhs.m_query));
}


///
bool URI::operator !=(const IO::URI & rhs) const 
{
	return ((this->m_isEmpty != rhs.m_isEmpty) ||
		(this->m_scheme != rhs.m_scheme) ||
		(this->m_userinfo != rhs.m_userinfo) ||
		(this->m_host != rhs.m_host) ||
		(this->m_port != rhs.m_port) ||
		(this->m_localpath != rhs.m_localpath) ||
		(this->m_fragment != rhs.m_fragment) ||
		(this->m_query != rhs.m_query));
}



///
bool URI::IsEmpty() const 
{
	return this->m_isEmpty;
}


///
void URI::Clear()
{
	this->m_isEmpty = true;
	this->m_scheme.Clear();
	this->m_fragment.Clear();
	this->m_host.Clear();
	this->m_localpath.Clear();
	this->m_port.Clear();
	this->m_query.Clear();
	this->m_userinfo.Clear();
}



///
void URI::Set(const Helper::String & str)
{
	this->Split(str);
}



///
void URI::SetFragment(const Helper::String &frag)
{
	this->m_fragment = frag;
}


///
void URI::SetHost(const Helper::String &host)
{
	this->m_host = host;
}


///
void URI::SetLocalPath(const Helper::String &path)
{
	this->m_localpath = path;
}


///
void URI::SetPort(const Helper::String &port)
{
	this->m_port = port;
}


///
void URI::SetQuery(const Helper::String &query)
{
	this->m_query = query;
}


///
void URI::SetScheme(const Helper::String &scheme)
{
	this->m_scheme = scheme;
}


///
void URI::SetUserInfo(const Helper::String &userinfo)
{
	this->m_userinfo = userinfo;
}


///
const Helper::String & URI::GetFragment() const
{
	return this->m_fragment;
}


///
const Helper::String & URI::GetHost() const
{
	return this->m_host;
}


///
const Helper::String & URI::GetLocalPath() const
{
	return this->m_localpath;
}


///
const Helper::String & URI::GetPort() const
{
	return this->m_port;
}


///
const Helper::String & URI::GetQuery() const
{
	return this->m_query;
}


///
const Helper::String & URI::GetScheme() const
{
	return this->m_scheme;
}


///
const Helper::String & URI::GetUserInfo() const
{
	return this->m_userinfo;
}



///
Helper::String URI::GetAsString() const
{
	return this->Build();
}





///
bool URI::Split(const Helper::String & str) 
{
	return true;
}


///
Helper::String URI::Build() const
{
	Helper::String result;

	result.Reserve(256);

	if(this->m_scheme.IsValid())
	{
		result.Add(this->m_scheme);

		result.Add("://");
	}

	if(this->m_userinfo.IsValid())
	{
		result.Add(this->m_userinfo);

		result.Add("@");
	}

	if(this->m_host.IsValid())
		result.Add(this->m_host);

	if(this->m_port.IsValid())
	{
		result.Add(":");

		result.Add(this->m_port);
	}

	if(this->m_localpath.IsValid())
	{
		result.Add("/");

		result.Add(this->m_localpath);
	}

	if(this->m_fragment.IsValid())
	{
		result.Add("#");

		result.Add(this->m_fragment);
	}

	if(this->m_query.IsValid())
	{
		result.Add("?");

		result.Add(this->m_query);
	}

	return result;
}

}